package org.java.demo;

import org.apache.poi.ss.usermodel.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Demo3 {
    public static void main(String[] args) throws FileNotFoundException {
        //读取excel
        File file = new File("D:\\workgadget\\files\\Demo3\\2月底测试数据集V2.xlsx");
        FileInputStream fis = new FileInputStream("D:\\workgadget\\files\\Demo3\\2月底测试数据集V2.xlsx");


        ArrayList<String> sheet0List = new ArrayList<>();
        ArrayList<String> sheet1List = new ArrayList<>();

        ArrayList<String> newList = new ArrayList<>();


        try {
            Workbook workbook = WorkbookFactory.create(fis);
            Sheet sheet0 = workbook.getSheetAt(0);
            Sheet sheet1 = workbook.getSheetAt(1);

            //取产品
            for (Row row0:sheet0){
                int rowNum = row0.getRowNum();
                for (Cell cell0:row0){
                    int cellType = cell0.getCellType();
                    int columnIndex = cell0.getColumnIndex();
                    //当前行为第一行则是标题
                    if(rowNum == 0){

                    }else {
                        if(columnIndex == 2){
                            String stringCellValue = cell0.getStringCellValue();
                            sheet0List.add(stringCellValue);
                        }
                    }
                }
            }
            //取问句
            for (Row row1:sheet1){
                int rowNum = row1.getRowNum();
                for (Cell cell1:row1){
                    int columnIndex = cell1.getColumnIndex();
                    //当前行为第一行则是标题
                    if(rowNum == 0){

                    }else {
                        if(columnIndex == 0){
                            String stringCellValue = cell1.getStringCellValue().toString();
                            sheet1List.add(stringCellValue);
                        }
                    }
                }
            }

            //循环产品，将名称替换到问题清单
            for (String prdName:sheet0List){
                for(String ques:sheet1List){
                    String replace = ques.replace("<产品名称>", prdName);
                    newList.add(replace);
                    System.out.println(replace);
                }
            }
            System.out.println("******************************************");

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
